<extend name="Public:base" />
<block name="content">
<div class="row-fluid">

	<div class="span12">
		
            <div class="color-panel hidden-phone">

                <div class="color-mode-icons icon-color"></div>

                <div class="color-mode-icons icon-color-close" style="display: none;"></div>

                <div class="color-mode" style="display: none;">

                    <p>THEME COLOR</p>

                    <ul class="inline">

                        <li class="color-black color-default current" data-style="default"></li>

                        <li class="color-blue" data-style="blue"></li>

                        <li class="color-brown" data-style="brown"></li>

                        <li class="color-purple" data-style="purple"></li>

                        <li class="color-grey" data-style="grey"></li>

                        <li class="color-white color-light" data-style="light"></li>

                    </ul>

                    <label>

                        <span>Layout</span>

                        <select class="layout-option m-wrap small">

                            <option value="fluid" selected="">Fluid</option>

                            <option value="boxed">Boxed</option>

                        </select>

                    </label>

                    <label>

                        <span>Header</span>

                        <select class="header-option m-wrap small">

                            <option value="fixed" selected="">Fixed</option>

                            <option value="default">Default</option>

                        </select>

                    </label>

                    <label>

                        <span>Sidebar</span>

                        <select class="sidebar-option m-wrap small">

                            <option value="fixed">Fixed</option>

                            <option value="default" selected="">Default</option>

                        </select>

                    </label>

                    <label>

                        <span>Footer</span>

                        <select class="footer-option m-wrap small">

                            <option value="fixed">Fixed</option>

                            <option value="default" selected="">Default</option>

                        </select>

                    </label>

                </div>

            </div>

		<h3 class="page-title">

			Blog

			 <small>Blog文章管理和更多</small>

		</h3>

		<ul class="breadcrumb">

			<li>

				<i class="icon-home"></i>

				<a href="index.html">首页</a> 

				<span class="icon-angle-right"></span>

			</li>

			<li>

				<a href="/admin/blog/article/index">文章管理</a>

				<span class="icon-angle-right"></span>

			</li>

			<li><a href="/admin/blog/article/index">文章列表</a></li>

		</ul>

	</div>

</div>

<div class="row-fluid">

	<div class="span12">
		<div class="span12 responsive" data-tablet="span12 fix-offset" data-desktop="span12">

			<!-- BEGIN EXAMPLE TABLE PORTLET-->

			<div class="portlet box grey">

				<div class="portlet-title">

					<div class="caption"><i class="icon-user"></i>文章列表</div>

					<div class="actions">

						<a href="/admin/blog/article/add" class="btn blue"><i class="icon-pencil"></i> 添加</a>

						<div name="caozuo" class="btn-group">

							<a class="btn green" href="#" data-toggle="dropdown">

							<i class="icon-cogs"></i> 操作

							<i class="icon-angle-down"></i>

							</a>

							<ul name="caozuo" class="dropdown-menu pull-right">

								<li class="disabled" name="edit"><a href="#"><i class="icon-pencil"></i> 修改</a></li>

								<li class="divider"></li>

								<li class="disabled" name="delete"><a href="#"><i class="icon-trash"></i> 删除</a></li>

							</ul>

						</div>

					</div>

				</div>

				<div class="portlet-body">

					<div id="sample_2_wrapper" class="dataTables_wrapper form-inline" role="grid">
						<div class="row-fluid">
							<div class="span6">
			                    <div id="sample_2_length" class="dataTables_length">
			                        <label>
			                          <select size="1" name="sel" aria-controls="DataTables_Table_1">
			                                <option value="10" selected="selected">10</option>
			                                <option value="20">20</option>
			                                <option value="30">30</option>
			                                <option value="40">40</option>
			                                <option value="50">50</option>
			                                <option value="60">60</option>
			                                <option value="70">70</option>
			                                <option value="80">80</option>
			                                <option value="90">90</option>
			                                <option value="100">100</option>
			                            </select> 
			                            显示条数
			                        </label>
			                    </div>
			                </div>
			                <div class="span6">
			                    <div class="dataTables_filter" id="sample_2_filter">
			                        <label>搜索: <input name="keyword" type="text" aria-controls="sample_2" class="m-wrap small">
			                        </label>
			                    </div>
			                </div>
			            </div>
						<table class="table table-striped table-bordered table-hover dataTable" id="sample_2" aria-describedby="sample_2_info">

							<thead>

								<tr role="row">
									<th style="width: 24px;" class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" aria-label="">
										<div class="checker">
											<span name="allcheck" class="">
												<input type="checkbox" class="group-checkable" data-set="#sample_2 .checkboxes">
											</span>
										</div>
									</th>
									<th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Username: activate to sort column ascending" style="width: 20px;">id</th>
									<th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Email: activate to sort column ascending" style="width: 50px;">类别</th>
									<th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Status: activate to sort column ascending" style="width: 70px;">标题</th>
									<th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Username: activate to sort column ascending" style="width: 117px;">主图</th>
									<th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Email: activate to sort column ascending" style="width: 210px;">描述</th>
									<th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Status: activate to sort column ascending" style="width: 90px;">标签</th>
									<th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Username: activate to sort column ascending" style="width: 50px;">热度</th>
									<th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Email: activate to sort column ascending" style="width: 90px;">置顶</th>
									<th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Status: activate to sort column ascending" style="width: 90px;">状态</th>
									<th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Status: activate to sort column ascending" style="width: 60px;">操作者</th>
									<th class="hidden-480 sorting_desc" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Status: activate to sort column ascending" style="width: 122px;">更新时间</th>
								</tr>

							</thead>

						

							<tbody role="alert" aria-live="polite" aria-relevant="all" name="tbody">
								
							</tbody>
						</table>
						<div class="row-fluid">
				            <div class="span6">
				                <div class="dataTables_info" id="sample_2_info">
				                    
				                </div>
				            </div>
				            <div class="span6">
				                <div class="dataTables_paginate paging_bootstrap pagination">
				                   
				                     <div class="dataTables_paginate paging_full_numbers" id="DataTables_Table_1_paginate">
				                            <a tabindex="0" href="javascript:void(0);" class="first paginate_button paginate_button_disabled" id="DataTables_Table_1_first">
				                                第一页
				                            </a>
				                            <a tabindex="0" href="javascript:void(0);" class="previous paginate_button paginate_button_disabled" id="DataTables_Table_1_previous">
				                                上一页
				                            </a>
				                            <span id="limit">
				                                
					                            
					                            <span>共<span name="maxPage">8</span>页</span>
				                            </span>
				                             <a tabindex="0" href="javascript:void(0);" class="first paginate_button" id="DataTables_Table_1_next">下一页</a>
				                             <a tabindex="0" href="javascript:void(0);" class="previous paginate_button " id="DataTables_Table_1_last">最后一页</a>
				                      
				                    </div>
				                 </div>
				             </div>
				         </div>
						
					</div>

				</div>

			</div>

			<!-- END EXAMPLE TABLE PORTLET-->

		</div>
	</div>
</div>
<!-- <tr class="gradeX even"> -->
<script type="text/javascript" src="__PUBLIC__/admin/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
	liuxinAjax(10,1);
	$('input[name="keyword"]').keyup(function(){
		var search=$(this).val();
		var num=$('select[name="sel"]').val();
		liuxinAjax(num,1,search);
	});


	$('span[name="allcheck"]').click(function(){
		if($(this).attr('class')=='checked'){
			$(this).attr('class','');
			 $('span[name="check"]').each(function(){
				$('span[name="check"]').attr('class','');
			});
			$('li[name="delete"]').attr('class','');
		}else{
			$(this).attr('class','checked');
			 $('span[name="check"]').each(function(){
				$('span[name="check"]').attr('class','checked');
			});
		}
		$('li[name="edit"]').attr('class','disabled');
	});
	$('span[name="check"]').live('click',function(){
		if($(this).attr('class')=='checked'){
			$(this).attr('class','');
			var aa=($('span[name="check"][class="checked"]').length);
			var bb=$('select[name="sel"]').val();
			if(aa!=bb){
				$('span[name="allcheck"]').attr('class','');
			}
			if(aa==1){
				$('li[name="edit"]').attr('class','');
				$('li[name="delete"]').attr('class','');
			}else{
				$('li[name="edit"]').attr('class','disabled');
			}
			if(aa=0){
				$('li[name="delete"]').attr('class','disabled');
			}
		}else{
			$(this).attr('class','checked');
			var aa=($('span[name="check"][class="checked"]').length);
			var bb=$('select[name="sel"]').val();
			if(aa==bb){
				$('span[name="allcheck"]').attr('class','checked');
			}
			if(aa==1){
				$('li[name="edit"]').attr('class','');
				$('li[name="delete"]').attr('class','');
			}else{
				$('li[name="edit"]').attr('class','disabled');
			}
			if(aa=0){
				$('li[name="delete"]').attr('class','disabled');
			}

			
		}
	});
	$('select[name="sel"]').change(function(){
		var num=$('select[name="sel"]').val();
		var search=$('input[name="keyword"]').val();
		liuxinAjax(num,1,search);
	});
	$('#DataTables_Table_1_first').click(function(){
		var num=$('select[name="sel"]').val();
		var search=$('input[name="keyword"]').val();
		liuxinAjax(num,1,search);
	});
	$('#DataTables_Table_1_previous').click(function(){
		var num=$('select[name="sel"]').val();
		var page=parseInt($('a[class="paginate_active"]').html())-1;
		var search=$('input[name="keyword"]').val();
		liuxinAjax(num,page,search);
	});
	$('#DataTables_Table_1_next').click(function(){
		var num=$('select[name="sel"]').val();
		var page=parseInt($('a[class="paginate_active"]').html())+1;
		var search=$('input[name="keyword"]').val();
		liuxinAjax(num,page,search);
	});
	$('#DataTables_Table_1_last').click(function(){
		alert('last');
	});

	$('#limit a').live('click',function(){
		// console.log(maxPage);
		var num=$('select[name="sel"]').val();
		var page=$(this).html();
		var search=$('input[name="keyword"]').val();
		liuxinAjax(num,page,search);
	});

	$('select[name="top"]').change(function(){
		// alert('aa');
		var id=$(this).parent().parent().prevAll().eq('6').html();
		var top=$(this).val();

		// console.log(top);
		$.ajax({
			url:'/admin/blog/article/uptop',
			data:{'id':id,'top':top,},
			type:'post',
			success:function(mes){
				if(mes=='yes'){
					// alert(top+'成功');
					if(top==0){
						alert('恢复普通成功');
					}else if(top==1){

						alert('文章置顶成功');
					}
				}else{
					if(top==0){
						alert('恢复普通失败');
					}else if(top==1){

						alert('文章置顶失败');
					}
				}
			}
		});
	});

	$('select[name="status"]').change(function(){
		// alert('aa');
		var id=$(this).parent().parent().prevAll().eq('7').html();
		var status=$(this).val();

		// console.log(id);
		$.ajax({
			url:'/admin/blog/article/upstatus',
			data:{'id':id,'status':status,},
			type:'post',
			success:function(mes){
				// console.log(mes);
				if(mes=='yes'){
					// alert(top+'成功');
					if(status==2){
						alert('放入回收站成功');
					}else if(status==1){

						alert('文章上传成功');
					}else if(status==0){

						alert('文章不上传成功');
					}
				}else{
					if(status==2){
						alert('放入回收站失败');
					}else if(status==1){

						alert('文章上传失败');
					}else if(status==0){

						alert('文章不上传失败');
					}
				}
			}
		});
	});

	$('li[name="delete"]').click(function(){
		// alert('aa');
		if($('span[class="checked"]').length!='0'){
			var ids=[];
			$('span[class="checked"]').each(function(i){
				ids[i]=$(this).parent().parent().next().html();
			});
			$.ajax({
				url:'/admin/blog/article/del',
				data:{'ids':ids},
				type:'post',
				dataType:'json',
				success:function(mes){
					// console.log(mes);
					if(mes=='yes'){
						alert('批量删除成功');
						location.href="/admin/blog/article/index";
					}else{
						$(mes).each(function(i){
							alert('批量删除第'+mes[i]+'条失败');
							location.href="/admin/blog/article/index";
						});
					}
				}
			});
		}else{
			alert('请至少选择一篇文章进行删除操作');
			location.href="/admin/blog/article/index";
		}
	});

	$('li[name="edit"]').click(function(){
		// alert('aa');
		// console.log($('span[class="checked"]').length);
		if($('span[class="checked"]').length=='1'){
			var id=$('span[class="checked"]').parent().parent().next().html();
			location.href='/admin/blog/article/edit?id='+id;
		}else if($('span[class="checked"]').length=='0'){
			alert('请选择一篇文章进行修改');
			location.href="/admin/blog/article/index";
		}else{
			alert('只能选择一篇文章进行修改');
			location.href="/admin/blog/article/index";
		}
	});

	function liuxinAjax(num,page,search){
		if(page<1){
			page=1;
		}else if(page>$('span[name="maxPage"]').html()){
			page=$('span[name="maxPage"]').html();
		}
		$.ajax({
			url:'/admin/blog/article/sel',
			data:{'num':num,'page':page,'keyword':search},
			type:'post',
			dataType:'json',
			async:false,
			success:function(mes){
				// console.log(mes);

				var tr=null;
				var a = null;
				$('tbody[name="tbody"] tr').remove();
				$(mes).each(function(i){
					if(mes.length-1==i){
						return ;
					}
					tr=$('<tr class="gradeX odd"><td class=" sorting_1"><div class="checker"><span name="check" class=""><input type="checkbox" class="checkboxes" value="1" checked="checked"></span></div></td><td class=" ">'+$(this).attr("id")+'</td><td class=" ">'+$(this).attr("type_name")+'</td><td class=" "><div style="width:70px;white-space:nowrap;overflow:hidden;text-overflow:hidden;text-overflow:ellipsis"><a href="#" title="'+$(this).attr("title")+'">'+$(this).attr("title")+'</a></div></td><td class=" "><img src="'+$(this).attr("pic")+'"style="width:100px;height:80px"></td><td class=" ">'+$(this).attr("introduce")+'</td><td name="label" class=" "><li style="display:none"><i class="icon-tags"></i> '+$(this).attr("label").split(',')[0]+'</li><li style="display:none"><i class="icon-tags"></i> '+$(this).attr("label").split(',')[1]+'</li><li style="display:none"><i class="icon-tags"></i> '+$(this).attr("label").split(',')[2]+'</li><li style="display:none"><i class="icon-tags"></i> '+$(this).attr("label").split(',')[3]+'</li></td><td class=" "><span name="hot" class="label ">'+$(this).attr("hot")+'&nbsp;&nbsp;℃</span></td><td class=" "><div id="sample_1_length" class="dataTables_length" style="width:25px"><select size="1" name="top" aria-controls="DataTables_Table_1" ><option value="0">普通</option><option value="1">置顶</option></select> </div></td><td class=" "><div id="sample_1_length" class="dataTables_length" style="width:25px"><select size="1" name="status" aria-controls="DataTables_Table_1" ><option value="1">上传</option><option value="0">不上传</option><option value="2">回收站</option></select> </div></td><td class=" ">'+$(this).attr("username")+'</td><td class=" ">'+$(this).attr("c_time")+'<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/admin/blog/article/pinglun?id='+$(this).attr("id")+'" title="查看完整的文章内容">文章评论<a/></td></tr>');
					

					$('tbody[name="tbody"]').append(tr);
					// console.log($(this).attr('label').split(',').length);	alert('aaa');
					if($(this).attr('label').split(',').length=='1'){
						$('td[name="label"]:eq('+i+') li:eq(0)').css('display','block');
					}else if($(this).attr('label').split(',').length=='2'){
						$('td[name="label"]:eq('+i+') li:eq(0)').css('display','block');
						$('td[name="label"]:eq('+i+') li:eq(1)').css('display','block');
					}else if($(this).attr('label').split(',').length=='3'){
						$('td[name="label"]:eq('+i+') li:eq(0)').css('display','block');
						$('td[name="label"]:eq('+i+') li:eq(1)').css('display','block');
						$('td[name="label"]:eq('+i+') li:eq(2)').css('display','block');
					}
					if($(this).attr('status')=='0'){
						$('select[name="status"]:eq('+i+')').val('0');
					}else if($(this).attr('status')=='1'){
						$('select[name="status"]:eq('+i+')').val('1');
					}else if($(this).attr('status')=='2'){
						$('select[name="status"]:eq('+i+')').val('2');
					}

					if($(this).attr('top')=='0'){
						$('select[name="top"]:eq('+i+')').val('0');
					}else if($(this).attr('top')=='1'){
						$('select[name="top"]:eq('+i+')').val('1');
					}

					if($(this).attr('hot')>='0' && $(this).attr('hot')<='30'){
						$('span[name="hot"]:eq('+i+')').attr('class','label label-primary');
					}else if($(this).attr('hot')>='31' && $(this).attr('hot')<='60'){
						// $('span[name="hot"]:eq('+i+')').attr('class','label label-info');
						$('span[name="hot"]:eq('+i+')').css('backgroundColor','LightSalmon');
					}else if($(this).attr('hot')>='61' && $(this).attr('hot')<='90'){
						$('span[name="hot"]:eq('+i+')').css('backgroundColor','tomato');
					}else if(parseInt($(this).attr('hot'))>=91 && parseInt($(this).attr('hot'))<=100){
						// $('span[name="hot"]:eq('+i+')').attr('class','label label-important');
						$('span[name="hot"]:eq('+i+')').css('backgroundColor','red');
					}
				});
				if(mes[mes.length-1]>=3){
					max=parseInt(page)+1;
					min=parseInt(page)-2;
					if(parseInt(page)<3){
						max=3;
						min=0;
					}
					if(parseInt(page)==mes[mes.length-1]){
						max=parseInt(page);
						min=parseInt(page)-3;
					}
				}else{
					max=mes[mes.length-1];
					min=0;
				}
				$('span[name=maxPage]').html(mes[mes.length-1]);	
				var span=null;
				$('#limit a').remove();
				for(var j=max;j>min;j--){
					if(j==page){
						span=$('<a tabindex="0" class="paginate_active">'+j+'</a>');
					}else{
						span=$('<a tabindex="0" class="paginate_button">'+j+'</a>');
					}					
					$('#limit').prepend(span);

				}

				var maxPage=$('span[name="maxPage"]').html();

				if($('#limit a:eq(0)').attr('class')=='paginate_active'){
					$('#DataTables_Table_1_first').attr('class','first paginate_button paginate_button_disabled');
					$('#DataTables_Table_1_previous').attr('class','previous paginate_button paginate_button_disabled');
				}
				if(page!=1){
					$('#DataTables_Table_1_first').attr('class','first paginate_button');
					$('#DataTables_Table_1_previous').attr('class','previous paginate_button');
				}else if(page==1){
					$('#DataTables_Table_1_first').attr('class','first paginate_button paginate_button_disabled');
					$('#DataTables_Table_1_previous').attr('class','previous paginate_button paginate_button_disabled');
				}
				if(page!=maxPage){
					$('#DataTables_Table_1_next').attr('class','first paginate_button');
					$('#DataTables_Table_1_last').attr('class','previous paginate_button ');
				}else if(page==maxPage){
					$('#DataTables_Table_1_next').attr('class','first paginate_button paginate_button_disabled');
					$('#DataTables_Table_1_last').attr('class','previous paginate_button paginate_button_disabled');
				}
			}
		});
	}
</script>
</block>